#!/usr/bin/env python


"""
GDP - Generic Data Processing
by Rogerio de Alencar Santos
2011/12
gpl v2
"""

##################################################
# Processador - Sistema de Processamento Generico
##################################################

import sys, time
from daemon import Daemon
from threads import ThreadEntrada
from threads import ThreadProcessamento
from threads import ThreadSaida

class MainDeamon(Daemon):
	def run(self):
		thr1 = ThreadEntrada()
		thr2 = ThreadProcessamento()
		thr3 = ThreadSaida()
		thr1.start()
		thr2.start()
		thr3.start()

if __name__ == "__main__":
	daemon = MainDeamon('/tmp/processador.pid')
	if len(sys.argv) == 2:
		if 'start' == sys.argv[1]:
			print "starting process..."
			daemon.start()
		elif 'stop' == sys.argv[1]:
			print "stoping process..."
			daemon.stop()
		elif 'restart' == sys.argv[1]:
			print "restarting process..."
			daemon.restart()
		else:
			print "Unknown command"
			sys.exit(2)
		sys.exit(0)
	else:
		print "usage: %s start|stop|restart" % sys.argv[0]
		sys.exit(2)
